﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using Bestlife.ERP.DataAccess;
using System.Data.SqlClient;
using System.Data;

public partial class Web_GeTables : System.Web.UI.Page
{
    SqlDataReader rdRStatus;
    DataTable BonusTB;
    protected void Page_Load(object sender, EventArgs e)
    {
        BonusTB = new DataTable();
        InitializeDataSource();
    }



    private void InitializeDataSource()
    {
        try
        {
            
            // Add four columns to the DataTable.
            BonusTB.Columns.Add("User_id");
            BonusTB.Columns.Add("Tpv");
            BonusTB.Columns.Add("ppv");
            BonusTB.Columns.Add("Cpv");
            BonusTB.Columns.Add("CPV_month");
            BonusTB.Columns.Add("T_sales");
            BonusTB.Columns.Add("T_commision");
            BonusTB.Columns.Add("T_Lship");
            BonusTB.Columns.Add("Subdealers_Id");
            BonusTB.Columns.Add("Bv");
            BonusTB.Columns.Add("user_Status");
            BonusTB.Columns.Add("Lship_Status");
            BonusTB.Columns.Add("Tbv");
            BonusTB.Columns.Add("Store_pv");
            BonusTB.Columns.Add("Store_bv");
            BonusTB.Columns.Add("Store_comm");
            BonusTB.Columns.Add("Store_Lship");
            BonusTB.Columns.Add("tppv_month");
            BonusTB.Columns.Add("tbv_month");

            // Set Produt_ID n Product_code column as the primary key.
            DataColumn[] dcKey = new DataColumn[1];
            //DataColumn[] dcKey2 = new DataColumn[1];
            dcKey[0] = BonusTB.Columns["User_id"];
            BonusTB.PrimaryKey = dcKey;
        }
        catch (Exception)
        {
            Response.Redirect("404.aspx");
        }

    }



    protected void Button1_Click(object sender, EventArgs e)
    {

     
        try
        {//try

            String connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
            Bestlife.ERP.DataAccess.clsCon.connect(connStr);


            String sqlstatus = "SELECT * from Bonus";

            rdRStatus = clsCon.ReadTable(sqlstatus);


            while (rdRStatus.Read())
            {
                Bestlife.ERP.Entities.E_Bonus Getbns = new Bestlife.ERP.Entities.E_Bonus();
                DataRow dr = BonusTB.NewRow();

                   dr["User_id"] =rdRStatus["User_id"].ToString();
                   dr["Tpv"] = decimal.Parse(rdRStatus["Tpv"].ToString());
                   dr["ppv"] = decimal.Parse(rdRStatus["ppv"].ToString());
                   dr["Cpv"] = decimal.Parse(rdRStatus["Cpv"].ToString());
                   dr["CPV_month"] = decimal.Parse(rdRStatus["CPV_month"].ToString());
                   dr["T_sales"] = decimal.Parse(rdRStatus["T_sales"].ToString());
                   dr["T_commision"] = decimal.Parse(rdRStatus["T_commision"].ToString());
                   dr["Subdealers_Id"] = rdRStatus["Subdealers_Id"].ToString();
                   dr["Bv"] = decimal.Parse(rdRStatus["Bv"].ToString());
                   dr["user_Status"] = rdRStatus["user_Status"].ToString();
                   dr["Lship_Status"] = decimal.Parse(rdRStatus["T_Lship"].ToString());
                   dr["Tbv"] = decimal.Parse(rdRStatus["Tbv"].ToString());
                   dr["Store_pv"] = decimal.Parse(rdRStatus["Store_pv"].ToString());
                   dr["Store_bv"] = decimal.Parse(rdRStatus["Store_bv"].ToString());
                   dr["Store_comm"] = double.Parse(rdRStatus["Store_comm"].ToString());
                   dr["tppv_month"] = decimal.Parse(rdRStatus["tppv_month"].ToString());
                   dr["tbv_month"] = decimal.Parse(rdRStatus["tbv_month"].ToString());
                   dr["Store_Lship"] = decimal.Parse(rdRStatus["Store_Lship"].ToString());

                
                   BonusTB.Rows.Add(dr);

            }



            DataView dv1 = new DataView(BonusTB);

            //GridView1.DataSource = dv1;
            //GridView1.DataBind();
            //int count = 0;
            //foreach (DataRowView drv in dv1)
            //{
            //    count++;
                
            //}

            //int rr = count;

        }//try


        catch (Exception err)
        {

        }

        finally
        {

            clsCon.conn_new.Close();
            rdRStatus.Close();
        }   //finally
    }
    protected void Button2_Click(object sender, EventArgs e)
    {

    }
}